package com.sanrenzu.chunbo.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sanrenzu.chunbo.R;
import com.sanrenzu.chunbo.bean.zxb.TuiJianChildBean;
import com.sanrenzu.chunbo.ui.vertical.fenlei.FenLeiActivity;

import java.util.List;

/**
 * Created by My on 2016/8/31.
 */
public class TuiJianAdapter extends BaseAdapter {

    private List<TuiJianChildBean> list = null;
    private Context context;
    private LayoutInflater inflater;
    public String id="";

    public TuiJianAdapter(Context context, List<TuiJianChildBean> list) {
        this.context = context;
        this.list = list;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        mViewHolder mHolder = null;
        if(convertView==null){
            convertView = inflater.inflate(R.layout.adapter_qianggou,parent,false);
            mHolder = new mViewHolder(convertView);
            convertView.setTag(mHolder);
        }else {
            mHolder = (mViewHolder) convertView.getTag();
        }
        id= list.get(position).getProductId()+"";
        mHolder.qianggou_mingceng_adapter_fragment.setText(list.get(position).getProductName());
        mHolder.qianggou_jiage_adapter_fragment.setText(list.get(position).getProductHotPrice()+"");
        Glide.with(context).load(list.get(position).getProductImage()+"").into(mHolder.qianggou_image_adapter_fragment);

        mHolder.qianggou_image_adapter_fragment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(context, FenLeiActivity.class);
                intent.putExtra("id",id);
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class mViewHolder {
        ImageView qianggou_image_adapter_fragment;
        TextView qianggou_mingceng_adapter_fragment;
        TextView qianggou_jiage_adapter_fragment;

        public mViewHolder(View convertView) {
            qianggou_image_adapter_fragment = (ImageView) convertView.findViewById(R.id.qianggou_image_adapter_fragment);
            qianggou_mingceng_adapter_fragment = (TextView) convertView.findViewById(R.id.qianggou_mingcheng_adapter_fragment);
            qianggou_jiage_adapter_fragment = (TextView) convertView.findViewById(R.id.qianggou_jiage_adapter_fragment);

        }
    }
}
